/******************************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd. 		              */
/*																              */
/*	NAME	  = t__sqlserver_bigint_add.c						              */
/*	NOTE	  = 												              */
/*	DATE	  = 2014/11/25 by geyh								              */
/******************************************************************************/

#include <stdio.h>
#include <CUnit/Basic.h>

#include "apmtest_cunit.h"
#include <db2/db2_core.h>
#include <db2/config.h>

extern int __db2_chk_cp(int i_ddm_cp, int *p_i_req_res);

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    int i_req_cp = 0;
    int i_ret = APM_L7_ANALYZE_SUCC;

    i_ret = __db2_chk_cp(0, &i_req_cp);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    return;
}

static void __case2(void)
{
    int i_req_cp = 0;
    int i_ret = APM_L7_ANALYZE_SUCC;

    i_ret = __db2_chk_cp(DRDA_CP_ACCRDB, &i_req_cp);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(i_req_cp, DB2_REQUEST);

    return;
}


static void __case3(void)
{
    int i_req_cp = 0;
    int i_ret = APM_L7_ANALYZE_SUCC;

    i_ret = __db2_chk_cp(DRDA_CP_BNDOPT, &i_req_cp);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(i_req_cp, DB2_REQUEST);

    return;
}

static void __case4(void)
{
    int i_req_cp = 0;
    int i_ret = APM_L7_ANALYZE_SUCC;

    i_ret = __db2_chk_cp(DRDA_CP_SQLCARD, &i_req_cp);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(i_req_cp, DB2_RESPONSE);

    return;
}

static void __case5(void)
{
    int i_req_cp = 0;
    int i_ret = APM_L7_ANALYZE_SUCC;

    i_ret = __db2_chk_cp(DRDA_CP_ACCRDBRM, &i_req_cp);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(i_req_cp, DB2_RESPONSE);

    return;
}

static void __case6(void)
{
    int i_req_cp = 0;
    int i_ret = APM_L7_ANALYZE_SUCC;

    i_ret = __db2_chk_cp(DRDA_CP_AGNPRMRM, &i_req_cp);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(i_req_cp, DB2_RESPONSE);

    return;
}

static void __case7(void)
{
    int i_req_cp = 0;
    int i_ret = APM_L7_ANALYZE_SUCC;

    i_ret = __db2_chk_cp(DRDA_CP_SECTKNOVR, &i_req_cp);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(i_req_cp, DB2_UNKNOW);

    return;
}

static void __case8(void)
{
    int i_req_cp = 0;
    int i_ret = APM_L7_ANALYZE_SUCC;

    i_ret = __db2_chk_cp(DRDA_CP_SYNCLOG, &i_req_cp);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(i_req_cp, DB2_UNKNOW);

    return;
}

int add_suite__db2_chk_cp(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __db2_chk_cp()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL ||
        CU_add_test(pSuite, "case4", __case4) == NULL ||
        CU_add_test(pSuite, "case5", __case5) == NULL ||
        CU_add_test(pSuite, "case6", __case6) == NULL ||
        CU_add_test(pSuite, "case7", __case7) == NULL ||
        CU_add_test(pSuite, "case8", __case8) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
